package interfaces;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.Input;

import states.SlickGame;

public class Controller {
	public void updateWASD(Input input, Controllable object){
		//1 Player
		//	Player 1: WASD and Space
		
		// W - Up
		if(input.isKeyDown(Input.KEY_W)){
			object.setUp(true);
			}
		else{object.setUp(false);}
		
		// S - Down
		if(input.isKeyDown(Input.KEY_S)){
			object.setDown(true);
			}
		else{object.setDown(false);}
		
		// A - Left
		if(input.isKeyDown(Input.KEY_A)){
			object.setLeft(true);
			}
		else{object.setLeft(false);}

		// D - Right
		if(input.isKeyDown(Input.KEY_D)){
			object.setRight(true);
			}
		else{object.setRight(false);}
		
		// Space - Special
		if(input.isKeyDown(Input.KEY_SPACE)){
			object.setSpecial(true);
			}
		else{object.setSpecial(false);}
	}
	
	public void updateStandard(Input input, Controllable object){
		//1 Player
		//	Player 1: Arrows and Space
		
		// Up
		if(input.isKeyDown(Input.KEY_UP)){
			object.setUp(true);
			}
		else{object.setUp(false);}
		
		// Down
		if(input.isKeyDown(Input.KEY_DOWN)){
			object.setDown(true);
			}
		else{object.setDown(false);}
		
		// Left
		if(input.isKeyDown(Input.KEY_LEFT)){
			object.setLeft(true);
			}
		else{object.setLeft(false);}

		// Right
		if(input.isKeyDown(Input.KEY_RIGHT)){
			object.setRight(true);
			}
		else{object.setRight(false);}
		
		// Space - Special
		if(input.isKeyDown(Input.KEY_SPACE)){
			object.setSpecial(true);
			}
		else{object.setSpecial(false);}
	}
	
	public void update2P(Input input, Controllable object1, Controllable object2){
		//Two Players
		//   Player 1: WASD and Space
		//   Player 2: Arrows and Enter
		
		//P1 W - Up
		if(input.isKeyDown(Input.KEY_W)){
			object1.setUp(true);
			}
		else{object1.setUp(false);}
		
		//P1 S - Down
		if(input.isKeyDown(Input.KEY_S)){
			object1.setDown(true);
			}
		else{object1.setDown(false);}
		
		//P1 A - Left
		if(input.isKeyDown(Input.KEY_A)){
			object1.setLeft(true);
			}
		else{object1.setLeft(false);}

		//P1 D - Right
		if(input.isKeyDown(Input.KEY_D)){
			object1.setRight(true);
			}
		else{object1.setRight(false);}
		
		//P1 Space - Special
		if(input.isKeyDown(Input.KEY_SPACE)){
			object1.setSpecial(true);
			}
		else{object1.setSpecial(false);}
		
		//P2 Up
		if(input.isKeyDown(Input.KEY_UP)){
			object2.setUp(true);
			}
		else{object2.setUp(false);}
		
		//P2 Down
		if(input.isKeyDown(Input.KEY_DOWN)){
			object2.setDown(true);
			}
		else{object2.setDown(false);}
		
		//P2 Left
		if(input.isKeyDown(Input.KEY_LEFT)){
			object2.setLeft(true);
			}
		else{object2.setLeft(false);}

		// Right
		if(input.isKeyDown(Input.KEY_RIGHT)){
			object2.setRight(true);
			}
		else{object2.setRight(false);}
		
		//P2 Enter - Special
		if(input.isKeyDown(Input.KEY_ENTER)){
			object2.setSpecial(true);
			}
		else{object2.setSpecial(false);}
	}
	
	public void updateAutoTrack(Controllable object, Trackable item, float errorTolerence){
		/* Remove tag to activate
		// Control X - Left/Right
		if(item.getX()<object.x-object.r*errorTolerence){object.setLeft(true);}
		else{object.setLeft(false);}
		
		if(item.getX()>object.x+object.r*errorTolerence){object.setRight(true);}
		else{object.setRight(false);}
		
		// Control Y - Up/Down
		if(item.getY()>object.y-object.r*errorTolerence){object.setDown(true);}
		else{object.setDown(false);}
		
		if(item.getY()<object.y+object.r*errorTolerence){object.setUp(true);}
		else{object.setUp(false);}
		
		// Control Special - Speed Up
		if((Math.abs(item.getX()-object.x)>SlickGame.width*errorTolerence)||(Math.abs(item.getY()-object.y)>SlickGame.height*errorTolerence)){
			object.setSpecial(true);
		}
		else{object.setSpecial(false);}
		
		/********/
		// Control X - Left/Right
		if(item.x-item.r*errorTolerence<object.x){object.setLeft(true);}
		else{object.setLeft(false);}
		
		if(item.x+item.r*errorTolerence>object.x){object.setRight(true);}
		else{object.setRight(false);}
		
		// Control Y - Up/Down
		if(item.y+item.r*errorTolerence>object.y){object.setDown(true);}
		else{object.setDown(false);}
		
		if(item.y-item.r*errorTolerence<object.y){object.setUp(true);}
		else{object.setUp(false);}
		
		// Control Special - Speed Up
		if((Math.abs(item.getX()-object.x)>SlickGame.width*errorTolerence)||(Math.abs(item.getY()-object.y)>SlickGame.height*errorTolerence)){
			object.setSpecial(true);
		}
		else{object.setSpecial(false);}
		
		/*******/
	}
	
	public void specialTrack(Controllable object, Trackable item, float error){
		object.specialUpdate(item, error);
	}
}
